package com.weigee.ktv.v.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import com.l.d.app.library.view.FocusedTextView;
import com.weigee.ktv.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import skin.support.widget.SkinCompatFrameLayout;

/**
 * Created by linde on 2017/04/28.
 * <p/>
 */
public final class SafetySettingsItemView extends SkinCompatFrameLayout {
    private ViewHolder mHolder;

    public SafetySettingsItemView(Context context) {
        this(context, null);
    }

    public SafetySettingsItemView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SafetySettingsItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        LayoutInflater.from(context).inflate(R.layout.safetysettings_frag___sv_item, this, true);
        String msg1 = null;
        String msg2 = null;
        if (attrs != null) {
            TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.SafetySettingsItemView);

            msg1 = array.getString(R.styleable.SafetySettingsItemView_safety_text_1);
            msg2 = array.getString(R.styleable.SafetySettingsItemView_safety_text_2);

            array.recycle();
        }
        setMsg(msg1, msg2);
    }

    public void setMsg(String msg1, String msg2) {
        initViewHolder();
        mHolder.tvMsg1.setText(msg1);
        mHolder.tvMsg2.setText(msg2);
    }

    private void initViewHolder() {
        if (mHolder == null) {
            mHolder = new ViewHolder(this);
        }
    }

    static class ViewHolder {
        @BindView(R.id.tv_msg_1)
        FocusedTextView tvMsg1;
        @BindView(R.id.tv_msg_2)
        FocusedTextView tvMsg2;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
